<?php


namespace Xy\Rbac\ModelTools;


class PaginateQueryModel
{
    const DEFAULT_PER_PAGE = 10;

    /**
     * @var int
     */
    protected $page;
    /**
     * @var int
     */
    protected $perPage;
    /**
     * @var integer
     */
    protected $firstQueryTime;

    public function __construct(array $pageInfo)
    {
        $this->setPage($pageInfo);
        $this->setPerPage($pageInfo);
    }

    /**
     * @param array $pageInfo
     */
    public function setPage(array $pageInfo)
    {
        $this->page = $pageInfo['page'] ?? 1;
    }

    /**
     * @param array $pageInfo
     */
    public function setPerPage(array $pageInfo)
    {
        $this->perPage = $pageInfo['per_page'] ?? self::DEFAULT_PER_PAGE;
    }

    /**
     * @return int
     */
    public function getPage(): int
    {
        return $this->page < 0 ? 1 : $this->page;
    }

    /**
     * @return int
     */
    public function getPerPage(): int
    {
        return $this->perPage;
    }
}